import 'package:flutter/material.dart';
import 'package:wechat/pages/chat/chat_page.dart';
import 'package:wechat/pages/discover/discover_page.dart';
import 'package:wechat/pages/friend/friends_page.dart';
import 'package:wechat/pages/Profile/profile_page.dart';

class RootPage extends StatefulWidget {
  const RootPage({Key? key}) : super(key: key);

  @override
  State<RootPage> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  int _currentIndex = 0;
  final List _pages = [
    ChatPage(),
    FriendsPage(),
    DiscoverPage(),
    ProfilePage(),
  ];
  final PageController _pageController = PageController(
    initialPage: 0,
  );

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        //appBar: AppBar(title: Text("WeXin"),),
        body: Container(
          //child: _pages[_currentIndex], //更新当前的child，那先前的就会释放掉
          child: PageView(
            controller: _pageController,
            onPageChanged: (int index) {
              _currentIndex = index;
              setState(() {});
            },
            physics: NeverScrollableScrollPhysics(), //不能横向滚动
            children: [
              ChatPage(),
              FriendsPage(),
              DiscoverPage(),
              ProfilePage(),
            ],
          ),
        ),
        bottomNavigationBar: BottomNavigationBar(
          //enableFeedback: false,
          type: BottomNavigationBarType.fixed,
          fixedColor: Colors.green,
          selectedFontSize: 12.0,
          currentIndex: _currentIndex,
          onTap: (index) {
            setState(() {
              _currentIndex = index;
              _pageController.jumpToPage(index);
            });
          },
          items: const [
            BottomNavigationBarItem(
              icon: ImageIcon(AssetImage("images/tabbar_chat.png")),
              label: "微信",
              activeIcon: ImageIcon(AssetImage("images/tabbar_chat_hl.png")),
              tooltip: '',
            ),
            BottomNavigationBarItem(
              icon: ImageIcon(AssetImage("images/tabbar_friends.png")),
              label: "通讯录",
              activeIcon: ImageIcon(AssetImage("images/tabbar_friends_hl.png")),
              tooltip: '',
            ),
            BottomNavigationBarItem(
              icon: ImageIcon(AssetImage("images/tabbar_discover.png")),
              label: "发现",
              activeIcon: ImageIcon(AssetImage("images/tabbar_discover_hl.png")),
              tooltip: '',
            ),
            BottomNavigationBarItem(
              icon: ImageIcon(AssetImage("images/tabbar_mine.png")),
              label: "我",
              activeIcon: ImageIcon(AssetImage("images/tabbar_mine_hl.png")),
              tooltip: '', //去掉长按吐司
            ),

          ],
        ),
      ),
    );
  }
}
